import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Enemigo1 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Enemigo2 extends Enemigo
{
    private final static int IMAGE_COUNT= 2;
    private static GreenfootImage[] imgs;
    public int invi=0;
    
    public Enemigo2()
    {
     init();
     setImage(imgs[0]);
    }
    
    public void act() 
    {  
        setImage(imgs[0]);
        Aspire w = (Aspire)getWorld();
        MueveEnemigo();
        w.retx(getX());
        Dispara(7);
        if(Greenfoot.getRandomNumber(1200)==4)
        invi=100;
        if(invi<1)
         Interseccion();
        else
        {
         invi--;
         setImage(imgs[1]);
        }
        
    }
    
    /**
     * Se mueve el enemigo
     */
    public void MueveEnemigo()
    {
        int xAux;
        xAux=getX()+2;
        if(xAux >= getWorld().getWidth()-1)
          xAux=0;
        setLocation(xAux, getY());
        }
    
    /**
     * Checa si hay intersecciones con algunos de los objetos
     */
    public void Interseccion()
    {
        Aspire w = (Aspire)getWorld();
        Actor balap = getOneIntersectingObject(Balapc.class);
        Actor balpo = getOneIntersectingObject(bapc.class);
        Actor bala = getOneIntersectingObject(Balajug.class);
        Actor balapo = getOneIntersectingObject(Balapod.class);
        if (balap != null)
        {
           Greenfoot.playSound("hit.wav");
           hit--;
          if(hit<=3)
          {
            w.addScorep(20);
            destroy();
          }
          
           
        }
        if (balpo != null)
        {
           Greenfoot.playSound("hit.wav");
           hit-=3;
          if(hit<=3)
          {
            w.addScorep(20);
            destroy();
          }
          
           
        }
        if (bala!= null)
        {
           Greenfoot.playSound("hit.wav");
           hit--;
          if(hit<=3)
          {
            w.addScore(20);
            destroy();
          }
          
           
        }
        if (balapo!= null)
        {
           Greenfoot.playSound("hit.wav");
           hit-=3;
          if(hit<=3)
          {
            w.addScore(20);
            destroy();
          }
          
           
        }
    } 
    
    /**
     * Arreglo de imagenes
     */
    private synchronized static void init() 
    {
        if(imgs == null) {
            imgs = new GreenfootImage[IMAGE_COUNT];
            for (int i = 0; i < IMAGE_COUNT; i++)
            {
            imgs[i] = new GreenfootImage("enemy2"+ (i+1) + ".png");
            
        }
        }
    }
    }
    

